package com.haierp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.PackageLevelMapper;
import com.haierp.mapper.PackageScaleMapper;
import com.haierp.model.PackageLevel;
import com.haierp.model.PackageScale;
import com.haierp.service.IPackageScaleService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.PackageLevelQueryVO;

/**
 * 
 * Title: PackageScaleServiceImpl.java
 * Description: 
 *
 * @author jc
 * Apr 8, 2017
 *
 */
@Service("packageScaleService")
public class PackageScaleServiceImpl extends SuperServiceImpl<PackageScaleMapper, PackageScale> implements IPackageScaleService {
	
	@Autowired
	private PackageScaleMapper packageScaleMapper;
	
	@Autowired
	private PackageLevelMapper packageLevelMapper;
	
	@Override
	public Integer queryPackageScalesCount(String name, String enName)
	{
		return packageScaleMapper.queryPackageScalesCount(name, enName);
	}
	
	@Override
	public JsonPageResult<List<PackageScale>> queryPackageScaleList() {
		JsonPageResult<List<PackageScale>> result = new JsonPageResult<>();
		
		List<PackageScale> packageScales = packageScaleMapper.queryPackageScales();
		result.setData(packageScales);
		
		return result;
	}

	@Override
	public JsonPageResult<List<PackageScale>> queryPackageScaleTree() {
		JsonPageResult<List<PackageScale>> result = new JsonPageResult<>();
		
		List<PackageScale> packageScales = packageScaleMapper.queryPackageScales();
		
		for (PackageScale packageScale : packageScales) {
			PackageLevelQueryVO packageLevelQueryVO = new PackageLevelQueryVO();
			packageLevelQueryVO.setFirstStart(0);
			packageLevelQueryVO.setPackageEn(packageScale.getEnName());
			packageScale.setPackageLevels(packageLevelMapper.queryPackageLevels(packageLevelQueryVO));
		}
		
		result.setData(packageScales);
		
		return result;
	}
}
